//
//  DetailMoBanViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/11/20.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "DetailMoBanViewController.h"
#import "UIImageView+AFNetworking.h"
@interface DetailMoBanViewController ()
@property(nonatomic,strong) UIButton *backBtn1;

@end

@implementation DetailMoBanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.titleLabel.text = @"商品详情";
    self.backBtn.hidden = YES;
    self.topView.hidden = NO;

    
    
    
    self.backBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 20, 44, 44)];
    [self.backBtn1 setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [self.backBtn1 addTarget:self action:@selector(back27:) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.backBtn1];


  
}


-(void)back27:(id)sender
{

    [self.navigationController popViewControllerAnimated:YES];


}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{
    return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 4;

}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return ViewHeight - 120 - 48* 4;

}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 120;


}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 48;

}




-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view1.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:view1];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((ViewWidth -120) /  2, 0, 120, 120)];
    
    
    if ([[self.detailDic objectForKey:@"image1"]  isEqualToString:@""]||  [[self.detailDic objectForKey:@"image1"] isKindOfClass:[NSNull class]]) {
        
        imageView.image = [UIImage imageNamed:@"backImage"];
        
        
        
    }
    
    else
    {
        
        NSString *str = [NSString stringWithFormat:@"%@",[self.detailDic objectForKey:@"image1"]];
        
        NSURL *url = [NSURL URLWithString:str];
        [imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"backImage"]];
    }
    
    [view1 addSubview:imageView];
    

    return view1;



}



-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{


    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];
    
    
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, ViewHeight - 120 - 48* 4)];
    textView.font = [UIFont systemFontOfSize:16];
    textView.textColor = [UIColor lightGrayColor];
    textView.text = [NSString stringWithFormat:@"   %@",[self.detailDic objectForKey:@"description"]];
    textView.editable = NO;
    [view1 addSubview:textView];



    
    
    return view1;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        
        
        //设定副标题
        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(ViewWidth *0.55, 0,  ViewWidth *0.45-10, 44)];
        lbl.font = [UIFont systemFontOfSize:15];
        lbl.textAlignment = NSTextAlignmentRight;
        lbl.textColor = [UIColor lightGrayColor];
        lbl.tag = 103;
        [cell addSubview:lbl];
    }
    
    
    UILabel *sublabel = (UILabel *) [cell viewWithTag:103];
    
    
    
    cell.textLabel.textColor = [UIColor grayColor];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"商品名称";
       
        sublabel.text = [self.detailDic objectForKey:@"product_name"];

    }
    else if (indexPath.row == 1)
    {
    
    cell.textLabel.text = @"商品产地";
        sublabel.text = [self.detailDic objectForKey:@"made_in"];

    
    }
    else if (indexPath.row == 2)
    {
        cell.textLabel.text = @"商品单价";
         sublabel.text = [self.detailDic objectForKey:@"unit_price"];

    
    }

    else
    {
    
        cell.textLabel.text = @"商品称重";

         sublabel.text = [self.detailDic objectForKey:@"product_unit"];
    
    }
    
    
    
    
    return cell;
    



}


@end
